let middleshop = document.querySelector(".goods");
// let obj = new URLSearchParams(location.search);
// let id = obj.get("id");
        window.onload = function () {
            let shopapi = "http://jx.xuzhixiang.top/ap/api/cart-list.php"
            let id = localStorage.getItem("id");
            console.log(id);
            axios.get(shopapi, {
                    params: {
                        id,

                    }
                })
                .then((r) => {
                    console.log(r)
                    let rr = r.data.data;
                    console.log(rr);
                    let ahtml = rr.map((v)=> `<table>
                        <tr>
                            <a href=""></a>
                            <td><img src="${v.pimg}" alt=""></td>
                            <td > ${v.pname}</td>
                            <td >${v.pdesc}</td>
                            <td class="tda" >1</td>
                             <td ><a><button class="btn1" onclick="delfn(${v.pid})">删除</button></a></td>
                            
                            </a>
                        </tr>
                    </table>`)
                       
                    
                    middleshop.innerHTML = ahtml
                    // middleshop2.innerHTML = ahtml
                    // middleshop3.innerHTML = ahtml
                    // middleshop4.innerHTML = ahtml
                    // middleshop5.innerHTML = ahtml
                    // middleshop6.innerHTML = ahtml
                })
        }

        async function btngwc() {

  
  let uid = localStorage.getItem("id")
  let obj = new URLSearchParams(location.search);
  let pid = obj.get("id");
  // console.log(id);
  
  // 接口地址：http://jx.xuzhixiang.top/ap/api/add-product.php
  // 接口请求方式：get
  // 接口参数：
  //      uid  用户id
  //      pid  商品id
  //      pnum  要添加的商品数量

  // 使用方式

  //      http://jx.xuzhixiang.top/ap/api/add-product.php?uid=1&pid=1&pnum=1
  //      服务器返回json数据

  let giveapi = "http://jx.xuzhixiang.top/ap/api/add-product.php";
  let res = await axios.get(giveapi, { params: { uid, pid, pnum:1 } })
    .then((vv) => console.log(vv))



  
      }
      async function delfn(pid) {
        let delapi = "http://jx.xuzhixiang.top/ap/api/cart-delete.php";
        //  let aaaa = {uid,pid,token};
        //  console.log(aaaa);

        let uid = localStorage.getItem("id");
        // let token2 = localStorage.getItem("token");

        // console.log(localStorage.getItem("id"));
        let uid1 = localStorage.getItem("id");
        console.log(uid1);
        let token = localStorage.getItem("token");

        axios
          .get(delapi, {
            params: {
              pid,
              uid,
            //   token:token2,/
            },
          })
          .then((r) => {
            console.log(r);
            // location.reload()
          });
          location.reload()
      }